<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
<?php
/**
* 创建类
*/
class ShopProduct
{
    
}

$p1 = new ShopProduct();
$p2 = new ShopProduct();

var_dump($p1,$p2);


// 类的属性
/**
* 类属性演示
*/
class ShopProduct1
{
   public $price = 0;
   public $spName = '';
   public $factory = '';
   private $cost = 0; 

   public function getCost()
   {
      return $this->cost;
   }

   private function setCost($value = 0)
   {
       $this->cost = $value;
   }
}

$p2 = new ShopProduct1();

$p2->spName = 'PHP入门培训';
var_dump($p2->price,$p2->spName);
var_dump($p2->getCost());

/**
* 构造函数
*/
class ShopProduct2 extends ShopProduct1
{
    
    function __construct($price, $spName, $factory, $cost)
    {
        $this->price = $price;
        $this->spName = $spName;
        $this->factory = $factory;
        $this->cost = $cost;
    }
}

$p3 = new ShopProduct2(99.9, 'php培训服务', 'aliyun', 10);
$p3->setCost(10);
var_dump($p3->spName);
?>
</body>
</html>